package javbot.command;

import java.awt.AWTException;
import java.awt.event.InputEvent;

public class CmdEvent extends Command {

	public static final int KEY_PRESS = 1;
	public static final int KEY_RELEASE = 2;

	public static final int MOUSE_PRESS_LEFT = 101;
	public static final int MOUSE_RELEASE_LEFT = 102;	
	public static final int MOUSE_PRESS_MIDDLE = 103;
	public static final int MOUSE_RELEASE_MIDDLE = 104;	
	public static final int MOUSE_PRESS_RIGHT = 105;
	public static final int MOUSE_RELEASE_RIGHT = 106;	

	private final int type;
	private final int code;
	
	public CmdEvent(int type, int code) throws AWTException {
		this.type = type;
		this.code = code;
	}

	public CmdEvent(int type) throws AWTException {
		this.type = type;
		this.code = -1;
	}


	public void execute() {
		switch(type) {
			case KEY_PRESS: robot.keyPress(code); break;
			case KEY_RELEASE: robot.keyRelease(code); break; 
			case MOUSE_PRESS_LEFT: robot.mousePress(InputEvent.BUTTON1_MASK); break; 
			case MOUSE_PRESS_MIDDLE: robot.mousePress(InputEvent.BUTTON2_MASK); break;
			case MOUSE_PRESS_RIGHT: robot.mousePress(InputEvent.BUTTON3_MASK); break;
			case MOUSE_RELEASE_LEFT: robot.mouseRelease(InputEvent.BUTTON1_MASK); break; 
			case MOUSE_RELEASE_MIDDLE: robot.mouseRelease(InputEvent.BUTTON2_MASK); break;
			case MOUSE_RELEASE_RIGHT: robot.mouseRelease(InputEvent.BUTTON3_MASK); break;			
		}
	}
	
	public String toString() {
		switch(type) {
			case KEY_PRESS: return "Key Press " + code;
			case KEY_RELEASE: return "Key Release " + code;
			case MOUSE_PRESS_LEFT: return "Mouse Press Left";
			case MOUSE_PRESS_MIDDLE: return "Mouse Press Middle";
			case MOUSE_PRESS_RIGHT: return "Mouse Press Right";
			case MOUSE_RELEASE_LEFT: return "Mouse Release Left";
			case MOUSE_RELEASE_MIDDLE:  return "Mouse Release Middle";
			case MOUSE_RELEASE_RIGHT: return "Mouse Release Right";				
		}
		
		return null;
				
	}	
	
}
